package com.freewater.library.catalogue.model.event;

import com.freewater.library.common.domain.DomainEvent;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import org.apache.commons.lang3.Validate;

import java.time.LocalDateTime;

/**
 * 书籍已创建事件
 */
@Getter
@EqualsAndHashCode
public class BookCreatedEvent implements DomainEvent {
    /**
     * ISBN
     */
    private final String isbn;
    /**
     * 创建时间
     */
    private final LocalDateTime occurAt;

    public BookCreatedEvent(String isbn) {
        this(isbn, LocalDateTime.now());
    }

    public BookCreatedEvent(String isbn, LocalDateTime occurAt) {
        Validate.notBlank(isbn, "ISBN不能为空");
        Validate.notNull(occurAt, "创建时间不能为空");
        this.isbn = isbn;
        this.occurAt = occurAt;
    }

    @Override
    public LocalDateTime occurAt() {
        return this.occurAt;
    }
}
